package com.gzbugu.polytechsasia.service.impl;

import com.gzbugu.polytechsasia.factory.DAOFactory;
import com.gzbugu.polytechsasia.service.IAddArticleService;
import com.gzbugu.polytechsasia.vo.Article;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;

/**
 * Created with IntelliJ IDEA.
 * User: Bokchoy
 * Date: 11/1/12
 * Time: 10:02 AM
 */
public class AddArticleService implements IAddArticleService {
    private static Logger log = LoggerFactory
            .getLogger(AddArticleService.class);

    @Override
    public boolean addArticle(String title, String content, int type) {
        log.debug("save article instance" + "content: " + content + "title: " + title + "type: " + type);
        Article instance = new Article(content, title, type);
        try {
            DAOFactory.getArticleDAO().save(instance);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Test
    public void asdh() throws UnsupportedEncodingException {
        addArticle("这是一个文章", "测试", 1);
        System.out.println("这是一个文章");
    }
}
